package com.demo.rabbitmq.producer;

import com.demo.rabbitmq.config.DirectExchangeEnum;
import com.demo.rabbitmq.config.DirectRoutingKeyEnum;
import com.demo.rabbitmq.model.User;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ExceptionProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void exception(int i) {
        String exchange = DirectExchangeEnum.DIRECT_EXCHANGE.getExchangeName();
        String queue = DirectRoutingKeyEnum.DIRECT_EXCEPTION_QUEUE_ROUTING_KEY.getRoutingKeyName();

//        String content = String.format("消息=%d，hello world! 当前时间：%s", i, new Date());
        User user = new User();
        user.setUserName("用户 " + new Date());
        user.setUserId(System.currentTimeMillis());
        rabbitTemplate.convertAndSend(exchange, queue, user);
    }
}
